import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:yp/config/index.dart';
import 'package:yp/helper.dart';
import 'package:yp/router.dart';

import 'logic.dart';
import 'state.dart';

class BusinessHallDetailsPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _BusinessHallDetailsPage();
  }
}

class _BusinessHallDetailsPage extends State<BusinessHallDetailsPage> {
  final BusinessHallDetailsLogic logic = Get.put(BusinessHallDetailsLogic());
  final BusinessHallDetailsState state =
      Get.find<BusinessHallDetailsLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        elevation: setWidth(1),
        backgroundColor: Colors.white,
        title: Text(
          '店铺详情',
          style: TextStyle(
            color: Color(0xff030303),
            fontSize: 17,
          ),
        ),
        iconTheme: IconThemeData(
          color: Color(0xff333333),
        ),
      ),
      body: GetBuilder<BusinessHallDetailsLogic>(
        builder: (logic) {
          return ListView(
            children: [
              Container(
                padding: EdgeInsets.only(
                  left: setWidth(30),
                  top: setWidth(34),
                  right: setWidth(30),
                  bottom: setWidth(78),
                ),
                color: Colors.white,
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Row(
                      mainAxisAlignment: MainAxisAlignment.start,
                      children: [
                        Image.asset(
                          'assets/images/shopIcon-white.png',
                          width: setWidth(40),
                          height: setWidth(40),
                          color: Config.mainColor,
                          fit: BoxFit.cover,
                        ),
                        SizedBox(
                          width: setWidth(20),
                        ),
                        Expanded(
                          child: Text(
                            state.data['sub_unit_name'],
                            style: TextStyle(
                              color: Color(0xff222222),
                              fontSize: 16,
                              fontWeight: FontWeight.bold,
                            ),
                          ),
                        ),
                      ],
                    ),
                    Padding(
                      padding: EdgeInsets.only(
                        top: setWidth(16),
                        bottom: setWidth(32),
                      ),
                      child: state.data['shop_photo'] == null
                          ? SizedBox(
                              height: setWidth(200),
                            )
                          : Image.network(
                              state.data['shop_photo'],
                              height: setWidth(200),
                              fit: BoxFit.cover,
                            ),
                    ),
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Column(
                          children: [
                            SizedBox(
                              height: setWidth(8),
                            ),
                            Image.asset(
                              'assets/images/locationIcon.png',
                              width: setWidth(20),
                              height: setWidth(26),
                              color: Color(0xffcccccc),
                              fit: BoxFit.fill,
                            ),
                          ],
                        ),
                        SizedBox(
                          width: setWidth(18),
                        ),
                        Expanded(
                          child: Text(
                            state.data['sub_unit_name'] +
                                state.data['prv_name'] +
                                state.data['city_name'] +
                                state.data['adr'],
                            style: TextStyle(
                              color: Color(0xff666666),
                              fontSize: 14,
                            ),
                          ),
                        ),
                      ],
                    ),
                    Padding(
                      padding: EdgeInsets.only(
                        top: setWidth(18),
                        bottom: setWidth(22),
                      ),
                      child: Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Image.asset(
                            'assets/images/telephone_icon.png',
                            width: setWidth(26),
                            height: setWidth(24),
                            fit: BoxFit.cover,
                          ),
                          Padding(
                            padding:
                                EdgeInsets.symmetric(horizontal: setWidth(20)),
                            child: Text(
                              state.data['telephone'],
                              style: TextStyle(
                                color: Color(0xff666666),
                                fontSize: 14,
                              ),
                            ),
                          ),
                          InkWell(
                            onTap: () {
                              print('电话联系 点击事件！！！！');
                              String telephone = state.data['telephone'];
                              if (telephone == null) {
                                return;
                              }
                              launch('tel://' + telephone);
                            },
                            child: Image.asset(
                              'assets/images/telephone_call.png',
                              width: setWidth(124),
                              height: setWidth(42),
                              fit: BoxFit.cover,
                            ),
                          ),
                        ],
                      ),
                    ),
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Column(
                          children: [
                            SizedBox(
                              height: setWidth(2),
                            ),
                            Image.asset(
                              'assets/images/clock_icon.png',
                              width: setWidth(26),
                              height: setWidth(26),
                              fit: BoxFit.cover,
                            ),
                          ],
                        ),
                        SizedBox(
                          width: setWidth(12),
                        ),
                        Text(
                          '营业时间: ' + state.data['business_hours'],
                          style: TextStyle(
                            color: Color(0xff666666),
                            fontSize: 14,
                          ),
                        ),
                      ],
                    ),
                    SizedBox(
                      height: setWidth(60),
                    ),
                    InkWell(
                      onTap: () {
                        if (kIsWeb) {
                          toast("请至应用市场下载“壹品慧”APP或微信搜索“壹品慧”小程序使用该功能。");
                          return;
                        }
                        print('去这里 点击事件！！！！');
                        Get.toNamed(RouteConfig.hallMap,
                            arguments: Get.arguments);
                      },
                      child: Container(
                        width: setWidth(540),
                        height: setWidth(88),
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(setWidth(44)),
                          border: Border.all(
                            color: Color(0xffea5504),
                            width: setWidth(2),
                          ),
                        ),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            Image.asset(
                              'assets/images/navigation_image.png',
                              width: setWidth(32),
                              height: setWidth(44),
                              fit: BoxFit.cover,
                            ),
                            Padding(
                              padding: EdgeInsets.symmetric(
                                  horizontal: setWidth(20)),
                              child: Text(
                                '去这里',
                                style: TextStyle(
                                  color: Color(0xffea5504),
                                  fontSize: 17,
                                ),
                              ),
                            ),
                            Text(
                              '距离您' +
                                  (double.parse(state.data['distance'].toString())*0.01).toStringAsFixed(2)+
                                  state.data['unit'],
                              style: TextStyle(
                                color: Color(0xffea5504),
                                fontSize: 12,
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ],
          );
        },
      ),
    );
  }
}
